package com.zzl.car.controller;

import com.alipay.api.AlipayApiException;
import com.zzl.car.entity.AliPayBean;
import com.zzl.car.entity.zdp;
import com.zzl.car.service.ZdpDemoService;
import com.zzl.car.util.AliPayUtil;
import com.zzl.car.zdpAnnotation.NotResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Map;

@CrossOrigin
@RestController
public class zdpDemo {

    @Autowired
    private ZdpDemoService zdpDemoService;
    @Autowired
    private AliPayUtil aliPayUtil;

    @GetMapping("/hello")
    public String hello1(){
        //System.out.println(id);
        return "hello,world";
    }


    @GetMapping("/getZdp")
    public zdp getZdp(){
        zdp allZdp = zdpDemoService.getAllZdp();
        System.out.println(allZdp);
        return allZdp;
    }

    @NotResponseBody
    @PostMapping("/payDemo")
    public String payDemo(@RequestBody AliPayBean aliPayBean){
        System.out.println(aliPayBean);
        String pay = null;
        try {
             pay = aliPayUtil.pay(aliPayBean);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        System.out.println("======== result ========");
        System.out.println(pay);
        return pay;
    }


    /*@GetMapping
    public String retrunurl(){
        return "hello";
    }*/

    @PostMapping("demo")
    public String zzwDemo(@RequestParam("image")MultipartFile image,@RequestParam("carBase")Map<String,Object>map){
        System.out.println(image);
        System.out.println(map.size());
        return "xxxx";
    }


}
